//
//  UserModel.m
//  YouYuanQianBao
//
//  Created by qiaofeng wu on 2017/11/29.
//  Copyright © 2017年 jiangwei. All rights reserved.
//

#import "UserModel.h"

@implementation UserModel
@synthesize mobile = _mobile;
@synthesize token = _token;
@synthesize first_login = _first_login;
+ (instancetype)shareUserModel {
    static UserModel *model;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        if (model == nil) {
            model = [[super alloc] init];
            model.name = @"未设置昵称";
            model.user_id = @"";
            model.headimgurl = @"";
        }
    });
    return model;
}

- (void)setupValuesForDictionary:(NSDictionary *)dic {
    self.name = STR_Is_NullOrEmpty(dic[@"nickname"]) ? @"未设置昵称":dic[@"nickname"];
    self.user_id = STR_Is_NullOrEmpty(SF(@"%@",dic[@"user_id"])) ? @"":dic[@"user_id"];
    self.mobile = STR_Is_NullOrEmpty(dic[@"mobile"]) ? @"":dic[@"mobile"];
    self.token = STR_Is_NullOrEmpty(dic[@"token"]) ? @"":dic[@"token"];
    self.headimgurl = STR_Is_NullOrEmpty(dic[@"pic"]) ? @"":dic[@"pic"];
    self.first_login = STR_Is_NullOrEmpty(SF(@"%@",dic[@"first_login"])) ? @"":dic[@"first_login"];
}
-(void)clearUserInfo{
    self.name = @"";
    self.user_id = @"";
    self.mobile = @"";
    self.token = @"";
    self.headimgurl = @"";
    self.first_login = @"";
}
- (void)setValue:(id)value forUndefinedKey:(NSString *)key {
    
}

- (void)setMobile:(NSString *)mobile {
    _mobile = mobile;
    NSUserDefaults *user = [[NSUserDefaults alloc] init];
    [user setObject:_mobile forKey:MobileKEY];
}

- (NSString *)mobile {
    NSUserDefaults *user = [[NSUserDefaults alloc] init];
    return [user valueForKey:MobileKEY];
}

- (void)setToken:(NSString *)token {
    _token = token;
    NSUserDefaults *user = [[NSUserDefaults alloc] init];
    [user setObject:_token forKey:TokenKEY];
}

- (NSString *)token {
    NSUserDefaults *user = [[NSUserDefaults alloc] init];
    return [user objectForKey:TokenKEY];
}

- (void)setFirst_login:(NSString *)first_login {
    _first_login = first_login;
    NSUserDefaults *user = [[NSUserDefaults alloc] init];
    [user setObject:SF(@"%@",_first_login) forKey:First_loginKEY];
}

- (NSString *)first_login {
    NSUserDefaults *user = [[NSUserDefaults alloc] init];
    return [user valueForKey:First_loginKEY];
}

- (BOOL)isLogin {
    NSUserDefaults *user = [[NSUserDefaults alloc] init];
    NSString *token = [user objectForKey:TokenKEY];
    if (token) {
        return YES;
    } else {
        return NO;
    }
}

@end
